﻿<Window x:Class="DemoDataBinding.GroupFilterSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:DemoDataBinding"
        Title="GroupFilterSample" Height="549" Width="579">
    <Window.Resources>
        <Style TargetType="ListBox">
            <Setter Property="Margin" Value="5"/>
        </Style>

        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="5"/>
        </Style>

        <Style TargetType="CheckBox">
            <Setter Property="Margin" Value="5"/>
        </Style>

        <GroupStyle x:Key="groupStyle">
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=Name}" 
                                       Background="LightGray"
                                       Foreground="Crimson"
                                       FontSize="16"
                                       FontWeight="Black"/>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>

        <Style TargetType="Button">
            <Setter Property="Padding" Value="5"/>
        </Style>

        <local:ReverseConverter x:Key="chose2enableConverter"/>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="3*"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="3*"/>
            </Grid.RowDefinitions>
            <Button Grid.Row="1" Content="&gt;&gt;"
                    Command="{Binding Path=SelectCmd}"/>
            <Button Grid.Row="3" Content="&lt;&lt;"
                    Command="{Binding Path=DeselectCmd}"/>
        </Grid>
        <GroupBox Header="All Students" Grid.Column="0">
            <DockPanel>
                <TextBox DockPanel.Dock="Top" 
                         Text="{Binding Path=SearchTxt4Add,UpdateSourceTrigger=PropertyChanged}"/>
                <CheckBox DockPanel.Dock="Bottom" Content="Select all to add"
                          Command="{Binding Path=SelectAllToAddCmd}"/>
                <ListBox ItemsSource="{Binding Path=ViewAllStudents}">
                    <ListBox.GroupStyle>
                        <StaticResource ResourceKey="groupStyle"/>
                    </ListBox.GroupStyle>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding Path=IsSelect4Add}" 
                              Content="{Binding Path=Name}"
                              IsEnabled="{Binding Path=IsChosen,Converter={StaticResource chose2enableConverter}}"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </DockPanel>
        </GroupBox>
        <GroupBox Header="Chosen Students" Grid.Column="2" >
            <DockPanel >
                <TextBox DockPanel.Dock="Top"
                         Text="{Binding Path=SearchTxt4Remove,UpdateSourceTrigger=PropertyChanged}"/>
                <CheckBox DockPanel.Dock="Bottom" Content="Select all to remove"
                          Command="{Binding Path=SelectAllToRemoveCmd}"/>
                <ListBox ItemsSource="{Binding Path=ViewChosenStudents}">
                    <ListBox.GroupStyle>
                        <StaticResource ResourceKey="groupStyle"/>
                    </ListBox.GroupStyle>
                    <ListBox.ItemTemplate>
                        <DataTemplate >
                            <CheckBox IsChecked="{Binding Path=IsSelect4Remove}" Content="{Binding Path=Name}"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </DockPanel>
        </GroupBox>
    </Grid>
</Window>
